package first;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.Format;
import java.util.ArrayList;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.XMLOutputter;



public class XMLoutput 
{
	private ArrayList<Tweet> tweets;
	
	public XMLoutput() throws IOException
    {
	}
	
	public void generator(ArrayList<Tweet> tweets2) throws IOException
	{
		this.tweets = tweets2;
    	
    	Element root = new Element("Tweets");
        Document dokument = new Document(root);
        
        for(int i = 0; i < tweets.size(); i++)
        {
        	if(tweets.get(i).getLanguage().equals("en"))
        	{
	        	root.addContent(new Element("Tweet"+i)
	        		.setAttribute("User", tweets.get(i).getUser())
	        		.setAttribute("Text", tweets.get(i).getText())
	        		.setAttribute("Updated", tweets.get(i).getUpdated())
	        		.setAttribute("Language", tweets.get(i).getLanguage())
	        		.setAttribute("Location", tweets.get(i).getLocation())
	        		.setAttribute("Picture", tweets.get(i).getPicture())
	        		.setAttribute("TextSent", tweets.get(i).getTextSent())
	        		.setAttribute("Rating", tweets.get(i).getRatingString())
	        		);
        	}
        }
    	   
        XMLOutputter outputter = new XMLOutputter();
        FileOutputStream output = new FileOutputStream("result.xml");
        outputter.output(dokument,output);
	}
}